<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>小鱼ADMIN</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/public/static/css/font.css">
    <link rel="stylesheet" href="/public/static/css/bgadmin.css">
    <script type="text/javascript" src="/public/static/js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/public/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/public/static/js/bgadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <style>
  .layui-input{height:30px;}
  .layui-form-label{line-height: 16px;}
  </style>
  <body>
    <div class="bg-body">
        <div class="layui-row">
          <form class="layui-form ">
            <input type="hidden" name="data_task" id="data_task" value="{$data_task}">
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">归属人：</label>
                <div class="layui-input-inline">
                  <select name="username" id="username" lay-verify="" autocomplete="off" class="layui-input" lay-search="">
                      <option value="">直接选择或搜索选择</option>  <!--请选择-->
                      {volist name="arrUsers" id="vo"}
                      <option value="{$vo.username}">{$vo.cn_name}   ( {$vo.username} ) </option>
                      {/volist}
                  </select>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">客户名称：</label>
                <div class="layui-input-inline">
                  <input type="text" name="customer_name" id= "customer_name" lay-verify="" autocomplete="off" class="layui-input">
                </div>
              </div>
              <a class="layui-btn layui-btn-small"  style="margin-bottom: 10px;" id="search"  lay-submit="" lay-filter="search"><i class="layui-icon" >&#xe615;</i></a>
            </div>
          </form>
        </div>
      <table class="layui-table" lay-data="{id: 'id', height:'full-200', url:'/index.php/crm/Datatask/dataTaskDetailData', where:{data_task:{$data_task}} , page:true, limit:10, limits:[5,10,20]}" lay-filter="task">
        <thead>
        <tr>
          <th lay-data="{checkbox:true, fixed: true}"></th>
          <th lay-data="{field:'id', align:'center', width:120}">客户编码</th>
          <th lay-data="{field:'customer_code', width:180, align:'center'}">客户编号</th>
          <th lay-data="{field:'customer_name', width:120, align:'center'}">客户名称</th>
          <th lay-data="{field:'username', width:120, align:'center'}">归属人</th>
          <th lay-data="{field:'expect_order_time', width:150, align:'center'}">预计开单时间</th>
          <th lay-data="{field:'expect_order_price', width:120, align:'center'}">预计开单金额</th>
          <th lay-data="{field:'order_time', width:150, align:'center'}">实际开单时间</th>
          <th lay-data="{field:'order_price', width:120, align:'center'}">实际开单金额</th>
          <th lay-data="{field:'customer_note', width:200, align:'center'}">客户备注</th>
          <th lay-data="{field:'task_status', width:80, align:'center'}">任务状态</th>
          <th lay-data="{fixed: 'right', width:120, align:'center', toolbar: '#barDemo'}">操作</th>
        </tr>
        </thead>
      </table>
      <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-mini" lay-event="customer">客户资料</a>
        <!-- <a class="layui-btn layui-btn-normal layui-btn-mini" lay-event="complete">完成任务</a> -->
      </script>
    </div>

</body>
<!-- <script type="text/javascript" src="/public/static/crm/js/customer/illness.js"></script> -->
<script>
    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(task)', function(obj){
            // console.log(obj)
        });

        //监听工具条
        table.on('tool(task)', function(obj){
            var data = obj.data;
            if(obj.event === 'complete'){
                layer.confirm('确定该条数据任务已完成吗？', function(index){
                    if (data.task_status == '已完成') {
                        layer.alert('任务已完成！', {icon: 5}, function(index){
                            layer.close(index)
                        });
                        return false;
                    }
                    $.ajax({
                        type: 'get',
                        url : '/index.php/crm/Datatask/completeDataTask',
                        data: 'id='+data.id+'&customer_code='+data.customer_code,
                        dataType: 'json',
                        success : function (result) {
                            if (result.success) {  
                                layer.alert(result.msg, {icon: 6}, function(index){
                                    location.replace(location.href);
                                });
                            } else {  
                                layer.alert(result.msg, {icon: 5}, function(index){
                                    layer.close(index)
                                }); 
                            }
                        }
                    })
                });
            } else if (obj.event === 'customer') {
                bg_full_show('编辑&nbsp;'+data.customer_name+'&nbsp;的资料','./editCustomer?customer_code='+data.customer_code+'&id='+data.id)
            }
        });

        //重载数据表
        $('#search').click(function(){
            var username = $("#username").val();
            var customer_name = $("#customer_name").val();
            var data_task = $("#data_task").val();
            table.reload('id', {
                url: 'dataTaskDetailData',
                where: {
                    username : username,
                    customer_name : customer_name,
                    data_task : data_task,
                } //设定异步数据接口的额外参数
            });
        });
    });

    $(document).on('dblclick', '.layui-table>tbody>tr', function (){
        var customer_code = $(this).children('td:eq(2)').text();
        var customer_name = $(this).children('td:eq(3)').text();
        bg_full_show('编辑&nbsp;'+customer_name+'&nbsp;的资料','./editCustomer?customer_code='+customer_code+'&id='+data.id)
    })
</script>

</html>